/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package meatslope2.gameengine.helpers;

import java.util.List;

/** A collection of miscellaneous utility functions. */
public final class Utils 
{
	// ===========================================================
	// Constants
	// ===========================================================
	
	private static final float EPSILON = 0.0001f;
	
	// ===========================================================
	// Methods
	// ===========================================================
	
    public final static int clamp(int value, int min, int max) 
    {
        if (value < min)
        	return min;
        else if(value > max)
        	return max;
        
        return value;
    }
    
    public final static float clampf(float value, float min, float max) 
    {
        if (value < min)
        	return min;
        else if(value > max)
        	return max;
        
        return value;
    }
    
    
    public final static int sign(float a) 
    {
        return a >= 0.0f ? 1 : -1;
    }
    
    public final static boolean close(float a, float b) 
    {
        return close(a, b, EPSILON);
    }

    public final static boolean close(float a, float b, float epsilon) 
    {
        return Math.abs(a - b) < epsilon;
    }
    
    public final static <T> T[] toArray(List<T> inputList, T[] inputArray)
    {
    	return (T[])inputList.toArray(inputArray);
    }
}
